// zhouyuyue_yajin/pages/orderDetails/orderDetails.js
let app = getApp();
let http = require('../../util/http.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    week_list:[{
      id:1,
      text:'周一'
    },{
      id:2,
      text:'周二'
    },{
      id:3,
      text:'周三'
    },{
      id:4,
      text:'周四'
    },{
      id:5,
      text:'周五'
    },{
      id:6,
      text:'周六'
    },{
      id:0,
      text:'周日'
    }],//日期列表
    week_sel:0,//日期id
    // order_list:[{
    //   "id": "1",
    //   "type": "10",//10:教师，20：学生
    //   "status": "20",//10:待配送，20：已配送
    //   "send_at": "1970-01-01 08:02",
    //   "format_week":'周四',
    //   "created_at": "1970-01-01 08:02:03",
    //   "realname": "孟先生",
    //   "avatarUrl":"xxxx.png",
    //   "phone": "18811773006",
    //   "schoolName": "sfd",
    //   "goodsCount": "2",
    //   "goodsFee": "3.00",
    //   "food":[
    //       {
    //           "name":"蔬菜一",
    //           "count":2,
    //           "fee":13
    //       },
    //       {
    //           "name":"蔬菜一",
    //           "count":2,
    //           "fee":13
    //       }
    //   ]
    // }],//订单列表
    order_list:[],
    // all_price:30,//总价
    pageSize:10,
    page:1,
  },

  // 获取订单详情
  getOrderList:function(){
    let that = this;
    http.get('order',{
      week:that.data.week_list[that.data.week_sel].id,
      page:that.data.page,
      pageSize:that.data.pageSize,
    },function(res){
      console.log('订单详情',res);
      that.setData({
        order_list:that.data.order_list.concat(res.data.data)
      });
    });
  },

  // 选择日期
  chooseWeek:function(e){
    let that = this;
    that.setData({
      week_sel:e.currentTarget.dataset.i,
      pageSize:10,
      page:1,
      order_list:[]
    });
    that.getOrderList();
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.getOrderList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let that = this;
    if(that.data.pageSize*that.data.page==that.data.order_list.length){
      that.setData({
        page:that.data.page + 1
      });
      that.getOrderList();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})